﻿using System;
using System.Windows.Forms;
using System.Reactive.Subjects;
using System.Threading.Tasks;
using ScottPlot;
using ReactiveChannelMessaging.Processors;
using ReactiveChannelMessaging.Core;

namespace ReactiveChannelMessaging.Processors;

public partial class Form1 : Form
{
    private FormsPlot _formsPlot;
    private RealTimeDataProcessor _realTimeDataProcessor;
    private readonly Subject<DataMessage> _dataSubject;

    public Form1(Subject<DataMessage> dataSubject)
    {
        InitializeComponent();
        this._dataSubject = dataSubject;
        InitializeScottPlot();
        InitializeRealTimeDataProcessor();
    }
    private void InitializeScottPlot()
    {
        _formsPlot = new FormsPlot
        {
            Dock = DockStyle.Fill,
            Location = new System.Drawing.Point(0, 0),
            Name = "formsPlot",
            Size = new System.Drawing.Size(800, 450),
            TabIndex = 0
        };

        this.Controls.Add(_formsPlot);
    }

    private void InitializeRealTimeDataProcessor()
    {
        _realTimeDataProcessor = new RealTimeDataProcessor(_formsPlot, _dataSubject);
    }

    /// <summary>
    /// 释放资源
    /// </summary>
    /// <param name="disposing">是否释放托管资源</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && _realTimeDataProcessor != null)
        {
            _realTimeDataProcessor.Dispose(); // 释放实时数据处理器资源
        }
        base.Dispose(disposing);
    }
}
